﻿using System;
using System.Runtime.InteropServices;

namespace MyBasicLib
{
    /// <summary>
    /// 
    /// </summary>
    public   class NativeMethods
    {
        [DllImport("rpcrt4.dll", SetLastError = true)]
        private static extern int UuidCreateSequential(out Guid guid);

        [DllImport("kernel32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool QueryThreadCycleTime(IntPtr threadHandle, ref ulong cycleTime);

        [DllImport("kernel32.dll")]
        internal static extern IntPtr GetCurrentThread();

        /// <summary>
        /// 创建有顺序的Guid
        /// </summary> 
        /// <returns></returns> 
        public static Guid UuidCreateSequential()
        {
            const int RPC_S_OK = 0;
            Guid g;
            int hr = UuidCreateSequential(out g);
            if (hr != RPC_S_OK)
                throw new Exception("UuidCreateSequential failed: " + hr);
            return g;
        }
    }
}